class Solution {
public:
    int monotoneIncreasingDigits(int n) {
        string num = to_string(n);
        int size = num.size();
        string ret;
        for (int i = 0; i < size; i++) {
            string tmp = ret + num[i];
            tmp.resize(size, num[i]);
            int t = stoi(tmp);
            if (t <= n)
                ret += num[i];
            else {
                ret += num[i] - 1;
                ret.resize(size, '9');
                break;
            }
        }
        return stoi(ret);
    }
};
/*
 1000
 1111
  999

 1352
 1349

 4321
 3999
*/